package xyz.robinbingo.rbtask.common.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import xyz.robinbingo.rbtask.common.enums.ResEnum;

import java.io.Serial;

/**
 * CustomException
 *
 * @author Robin
 * @date 2020/9/2 16:18
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class CustomException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 8090152045650120491L;
    private Integer code;
    private String message;

    public CustomException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public static CustomException of(ResEnum resEnum) {
        return new CustomException(resEnum.getCode(), resEnum.getMessage());
    }

    public static CustomException of(Integer code, String message) {
        return new CustomException(code, message);
    }

    public static CustomException of(String message) {
        return new CustomException(ResEnum.BUSINESS_ERROR.getCode(), message);
    }
}
